import { Entity, Column, PrimaryGeneratedColumn, UpdateDateColumn, ManyToOne, JoinColumn } from 'typeorm';
import { AdPosition } from "./ad_position.entities";
import { ApiProperty} from '@nestjs/swagger';
import { IsOptional } from 'class-validator';

@Entity()
export class Ad {
  @PrimaryGeneratedColumn({type: 'smallint'})
  id: number;

  @IsOptional()
  @ApiProperty()
  @Column({type: 'smallint' ,width: 5 })
  ad_position_id:number;

  @IsOptional()
  @ApiProperty()
  @Column({type: 'smallint' ,width: 5 })
  media_type: number;

  @IsOptional()
  @ApiProperty()
  @Column({type: 'varchar' ,length: 60 })
  name: string;

  @IsOptional()
  @ApiProperty()
  @Column({type: 'varchar' ,length: 255 })
  link: string;

  @IsOptional()
  @ApiProperty()
  @Column('text')
  image_url: string;

  @IsOptional()
  @ApiProperty()
  @Column({type: 'varchar', length: 255})
  content: string;

  @IsOptional()
  @ApiProperty()
  @UpdateDateColumn()
  end_time: Date;

  @IsOptional()
  @ApiProperty()
  @Column({type: 'tinyint', width: 3})
  enabled: number;

  @ManyToOne(type => AdPosition, ad_position => ad_position.ads,{
    cascade: true
  })
  @JoinColumn({
    name: 'ad_position_id'
  })
  adPosition: AdPosition
}
